home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / msjv6-5.zip / WINDOS.ZIP / MEM.C < prev    next >
C/C++ Source or Header  |  1991-09-01  |  930b  |  40 lines

  1. /* MEM.C */
  2.  
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <malloc.h>
  6. #include <string.h>
  7. #include <time.h>
  8.  
  9. main(int argc, char *argv[])
  10. {
  11.     char far *fp;
  12.     time_t t1, t2;
  13.     unsigned long bytes = 0;
  14.     unsigned long allocs = 0;
  15.     
  16.     unsigned blksize = (argc < 2) ? 1024 : atoi(argv[1]);
  17.     
  18.     time(&t1);
  19.     for (;;)
  20.         if ((fp = _fmalloc(blksize)) != 0)
  21.         {
  22.             _fmemset(fp, 0, blksize);    // touch every byte
  23.             *fp = 'x';
  24.             fp[blksize-1] = 'y';
  25.             bytes += blksize;
  26.             allocs++;
  27.             if ((allocs % 100) == 0)
  28.                 printf("%lu allocs, %lu bytes, %Fp, %lu seconds\n", 
  29.                     allocs, bytes, fp, time(&t2) - t1);
  30.         }
  31.         else
  32.             break;
  33.     
  34.     time(&t2);  
  35.     printf("Allocated %lu bytes, %lu allocs, %lu seconds\n", 
  36.         bytes, allocs, t2 - t1);
  37.  
  38.     return 0;
  39. }
  40.